/*  
	Author      : Sidek Sirun
	Course      : UCI Java Programming I (X460.10)
	Assignment 3: Collection of Person Objects

	Create a collection that holds objects of the Person class you created in Lesson 2. 
	Your program should print the size of the collection and utilize Generics to ensure 
	the collection only contains objects of type Person.

*/

import java.util.ArrayList;

class MyCollectionTest {
	/**
	* @main() method
	*/
	public static void main(String[] args) {
		// New collection for Person class that utilize Generics
		ArrayList<Person> personArray = new ArrayList<Person>();

		System.out.println("");
		System.out.println("===== MyCollectionTest =====");
		System.out.println("Size of PersonArray (before adding element): " + personArray.size());

		// Add new elements
		Person p0 = new Person("James",  "Bond",  49, "Male",   "011-70-7777");
		Person p1 = new Person("Lara",   "Croft", 25, "Female", "033-55-8888");
		Person p2 = new Person("Austin", "Power", 51, "Male",   "001-03-9999");
		Person p3 = new Person("Mary",   "Jane",  51, "Female", "010-05-9000");
		Person p4 = new Person("Clark",  "Kent",  39, "Male",   "100-50-1000");

		personArray.add(p0);
		personArray.add(p1);
		personArray.add(p2);
		personArray.add(p3);
		personArray.add(p4);

		// Try adding non-Person type
		//String t0 = "testABC";
		//personArray.add(t0);

		System.out.println("");
		System.out.println("Size of PersonArray (after adding element): " + personArray.size());

		// Print to STDOUT
		System.out.println("Collection contents:");
		for (int i = 0; i < personArray.size(); i++) {
			System.out.println("Person " + i + " info => " + personArray.get(i));
		}

		// Remove element
		System.out.println("");
		System.out.println("Removing element #3 => " + p2.toString());
		personArray.remove(p2);
		System.out.println("Size of PersonArray (after removing element): " + personArray.size());
		System.out.println("Collection contents:");
		for (int i = 0; i < personArray.size(); i++) {
			System.out.println("Person " + i + " info => " + personArray.get(i));
		}

		// Update element
		System.out.println("");
		Person p5 = new Person("Jen", "Law", 23, "Female", "202-22-2552");
		System.out.println("Updating element #4 with => " + p5.toString());
		personArray.set(3, p5);
		System.out.println("Size of PersonArray (after updating element): " + personArray.size());
		System.out.println("Collection contents:");
		for (int i = 0; i < personArray.size(); i++) {
			System.out.println("Person " + i + " info => " + personArray.get(i));
		}

		System.out.println("");
	}

}